home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / AEVT.c next >
Encoding:
C/C++ Source or Header  |  1995-12-20  |  4.6 KB  |  215 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************************
  2.  
  3.  
  4.                         Perform Apple Events
  5.                         
  6.                         Written by Peter Falco, Apple Computer
  7.                         
  8.                         April, 1995
  9.  
  10. *************************************************************************************************/
  11.  
  12.  
  13. #include <AppleEvents.h>
  14. #include <Drag.h>
  15. #include <GestaltEqu.h>
  16. #include <Memory.h>
  17. #include <SegLoad.h>
  18.  
  19. #include "QD3DtoQTVR.h"
  20. #include "AEVT.h"
  21. #include "extern.h"
  22. #include "file.h"
  23. #include "NavMovie.h"
  24. #include "document.h"
  25.  
  26.  
  27. void DoHighLevelEvent(EventRecord *ev)
  28. {
  29.     OSErr err;
  30.     
  31.     err = AEProcessAppleEvent(ev);    
  32. }
  33.  
  34.  
  35.  
  36. pascal OSErr MyAEHandleOAPP(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  37. {
  38.     OSErr err = noErr ;
  39.     SFTypeList            theTypeList = {'3DMF'};
  40.     StandardFileReply    theReply;
  41.             
  42.     *theAppleEvent = *theAppleEvent;
  43.      *reply = *reply;
  44.      refCon = refCon;
  45.     
  46.     StandardGetFilePreview(0L, 1, theTypeList, &theReply);
  47.  
  48.     while (theReply.sfGood)
  49.         {
  50.         MyConvert3DMFToObject(&theReply.sfFile);
  51.         StandardGetFilePreview(0L, 1, theTypeList, &theReply);
  52.         }
  53.         
  54.     SendQuitApp();
  55.  
  56.     return err;
  57. }
  58.  
  59.  
  60. //-----------------------------------------------------------------------
  61. // handler for the open document appleevent handler
  62.  
  63. pascal OSErr MyAEHandleODOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  64. {
  65.     FSSpec         myFSS;
  66.     AEDescList    docList;
  67.     OSErr        err,
  68.                 ignoreErr;
  69.     long        index,
  70.                 itemsInList;
  71.     Size         actualSize;
  72.     AEKeyword    keywd;
  73.     DescType    returnedType;
  74.  
  75.     *theAppleEvent = *theAppleEvent;
  76.      *reply = *reply;
  77.      refCon = refCon;
  78.      
  79.     err = AEGetParamDesc(theAppleEvent,keyDirectObject,typeAEList,&docList);
  80.     if (err == noErr) {
  81.     
  82.         // see how many descriptor items are in the list
  83.         // this is the number of documents we want to open
  84.         err = AECountItems(&docList,&itemsInList);
  85.  
  86.         // now get each descriptor record from the list
  87.         // coerce the returned data to an FSSpec record, and
  88.         // open the asoociated file
  89.         
  90.         for (index=1; index <= itemsInList && err == noErr; index++) {
  91.         
  92.             err = AEGetNthPtr(    &docList, 
  93.                                 index,
  94.                                 typeFSS,
  95.                                 &keywd,
  96.                                 &returnedType,
  97.                                 (Ptr)&myFSS,
  98.                                 sizeof(myFSS),
  99.                                 &actualSize);
  100.     
  101.             if (err == noErr)    {
  102.             
  103.                 FInfo        fndrInfo ;
  104.                 
  105.                 // we now have a valid FSSpec to reference the file, we need to know 
  106.                 // what type the file is to determine which file open function to call
  107.                 // we can determine this from the finder info for the file
  108.                 
  109.                 err = FSpGetFInfo( &myFSS, &fndrInfo );    
  110.                 
  111.                 // if we got that ok, then we switch on the file  
  112.                 // type (we don't care about the creator type)    
  113.                         
  114.                 if (err == noErr)    {
  115.                 
  116.                     switch( fndrInfo.fdType ) {
  117.                         case 'TEXT':
  118.                         case '3DMF':
  119.                             MyConvert3DMFToObject(&myFSS);
  120.                             break ;
  121.                         default:
  122.                             SendQuitApp();
  123.                             break ;
  124.                     }
  125.                 }
  126.             }
  127.         }
  128.         ignoreErr = AEDisposeDesc(&docList);
  129.         SendQuitApp();
  130.     }
  131.     return err ;
  132. }
  133.  
  134. //-----------------------------------------------------------------------
  135. // handler for the print document event handler
  136.  
  137. pascal OSErr MyAEHandlePDOC(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  138. {
  139.     return noErr;
  140. }
  141.  
  142.  
  143. pascal OSErr MyAEHandleQUIT(AppleEvent *theAppleEvent,AppleEvent *reply,long refCon)
  144. {
  145.     OSErr             err = noErr ;        // used as return value
  146.     WindowPtr        theWindow;
  147.     
  148.     // close all windows and signal to Quit
  149.     *theAppleEvent = *theAppleEvent;
  150.      *reply = *reply;
  151.      refCon = refCon;
  152.  
  153.     gQuitting = true;
  154.         
  155.     // attempt to close the document if window left open
  156.     theWindow = (WindowPtr)FrontWindow();
  157.     if (theWindow)
  158.         MyCloseDocument((DocumentPtr ) (((WindowPeek) theWindow)->refCon));
  159.     
  160.     // if we closed everything up successfully, we can return noErr, otherwise
  161.     // indicate to sender of the 'quit' aevt that we canceled
  162.     
  163.     if (gQuitting) {
  164.         gQuit = true;                        // user didn't cancel
  165.         err = AEDisposeDesc(&pSelfAddress);    // Dispose of my self-addressed descriptor.
  166.     }
  167.     else {
  168.         err = userCanceledErr ;
  169.     }
  170.             
  171.     return err ;
  172. }
  173.  
  174.  
  175.  
  176. void SendQuitApp( void )
  177. {
  178.     AppleEvent    myAppleEvent, reply;
  179.     OSErr    err;
  180.     
  181.     //    Create the Apple Event.
  182.     err = AECreateAppleEvent( kCoreEventClass, 
  183.                                   kAEQuitApplication, 
  184.                                   &pSelfAddress,
  185.                                   kAutoGenerateReturnID, 
  186.                                   kAnyTransactionID, 
  187.                                   &myAppleEvent);
  188.                                   
  189.     //    Send the Apple Event.
  190.       err = AESend( &myAppleEvent, 
  191.                         &reply, 
  192.                         kAENoReply+kAENeverInteract, 
  193.                         kAENormalPriority,
  194.                         kAEDefaultTimeout, 
  195.                         nil, 
  196.                         nil);
  197.                         
  198.       AEDisposeDesc(&myAppleEvent);                // Dispose of the Apple Event.
  199. } // SendQuitApp
  200.  
  201.  
  202. void SendOpenDoc(FSSpec *myFSSpec)
  203. {
  204.             
  205. }
  206.  
  207.  
  208.  
  209. void SendPrintDoc(FSSpec *myFSSpec)
  210. {
  211.  
  212.  
  213.  
  214.